﻿using Data;
using Factory;
using Hero;
using Services.Progress;
using UnityEngine;

namespace Services.Loot
{
    public class LootService : ILootService
    {
        private readonly ILootFactory _lootFactory;
        private readonly IProgressService _progressService;
        private GameSceneData _data;

        public LootService(ILootFactory lootFactory, IProgressService progressService)
        {
            _lootFactory = lootFactory;
            _progressService = progressService;
        }

        public void InitLootService(HeroHealth health, HeroReload reload, HeroScore score, HeroShoot shoot)
        {
            _data = _progressService.Progress.GameSceneData;
            _lootFactory.InitGameData(health, reload, score, shoot);
        }

        public void GenerateLoot(Vector3 at)
        {
            if (_data.Obstacles.Count == 0 && _data.Exit == null)
                _lootFactory.CreateExit(at);
            else
            {
                var random = Utils.GetRandomLootWeightedValue();
                switch (random)
                {
                    case "exit":
                        if (_data.Exit == null)
                            _lootFactory.CreateExit(at);
                        break;
                    case "gun":
                        _lootFactory.CreateGunBonus(at);
                        break;
                    case "life":
                        _lootFactory.CreateLifeBonus(at);
                        break;
                    case "ammo":
                        _lootFactory.CreateAmmoBonus(at);
                        break;
                    case "bomb":
                        _lootFactory.CreateBomb(at);
                        break;
                    case "empty":
                        break;
                }
            }
        }
    }
}